#!/usr/bin/env python3
import openpyxl
import sys
import os

def analyze_excel_file(filename):
    """分析Excel文件并返回详细内容"""
    try:
        workbook = openpyxl.load_workbook(filename, data_only=True)
        result = {}
        
        for sheet_name in workbook.sheetnames:
            sheet = workbook[sheet_name]
            sheet_data = []
            
            # 获取有数据的区域
            max_row = sheet.max_row
            max_col = sheet.max_column
            
            if max_row > 0 and max_col > 0:
                for row in range(1, min(max_row + 1, 100)):  # 增加到100行
                    row_data = []
                    for col in range(1, min(max_col + 1, 15)):  # 增加到15列
                        cell_value = sheet.cell(row=row, column=col).value
                        if cell_value is not None:
                            row_data.append(str(cell_value))
                        else:
                            row_data.append("")
                    
                    # 保留所有行，包括空行
                    sheet_data.append(row_data)
            
            result[sheet_name] = sheet_data
        
        return result
    
    except Exception as e:
        return {"error": str(e)}

def main():
    filename = "我的成果/架构设计/校园智作文技术方案.xlsx"
    if not os.path.exists(filename):
        print(f"文件未找到: {filename}")
        return
    
    print(f"=== 分析您的架构设计文档: {filename} ===")
    content = analyze_excel_file(filename)
    
    if "error" in content:
        print(f"错误: {content['error']}")
        return
    
    for sheet_name, sheet_data in content.items():
        print(f"\n=== 工作表: {sheet_name} ===")
        if not sheet_data:
            print("(空工作表)")
            continue
            
        for i, row in enumerate(sheet_data):
            if i >= 80:  # 限制显示行数
                print("  ...")
                break
            
            # 只显示有内容的行
            if any(cell.strip() for cell in row if cell):
                # 显示所有列
                print(f"  行{i+1}: {' | '.join(row)}")

if __name__ == "__main__":
    main() 